<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>
<%@include file="../common/selfCss.jsp"%>
<script type="text/javascript">
  
	$(function() {
		$("#add_artPic_form").validate({
			success : function(label) {
				label.text("").addClass("validate_success");
			},
			rules : {
				painter : {
					required : true,
					minlength : 2,
					maxlength : 20
				},
				artSize : {
					required : true

				},
				material : {
					required : true,
					minlength : 2,
					maxlength : 20
				},
				title : {
					required : true,
					minlength : 2,
					maxlength : 16
				}

			},
			messages : {
				painter : {
					required : "请输入画的作者名",
					minlength : "请填写2个以上字",
					maxlength : "请填写20个以下的字"
				},
				artSize : {
					required : "请输入画的作者名",
					minlength : "请填写2个以上字",
					maxlength : "请填写20个以下的字"
				},
				material : {
					required : "请输入画的作者名",
					minlength : "请填写2个以上字",
					maxlength : "请填写20个以下的字"
				},
				title : {
					required : "请输入画的作者名",
					minlength : "请填写2个以上字",
					maxlength : "请填写20个以下的字"
				}

			},
			submitHandler : function() {
				//var company = "";
				/* if($("#user_type_select").val() == "company"){
					company = $("#company").val();
				} */
				$.post("/misc/artPic/insertArtPic.htm", {
					painter : $("#painter").val(),
					artSize : $("#artSize").val(),
					material : $("#material").val(),
					title : $("#title").val(),
					content : $("#content").val(),
					count : $("#count").val(),
					price : $("#price").val(),
					classId : $("#classId").val(),//类型id
					type : $("#type").val(), //图片类型
					years : $("#years").val(),
					imagePath : $("#image").val(),
					imagePath2 : $("#image2").val(),
					imagePath3 : $("#image3").val(),
					imagePath4 : $("#image4").val(),
					imagePath5 : $("#image5").val(),
					artClass : $("#parent_val").val(), //分类
					priceMax:$("#priceMax").val(),
					oldWidth1 : $("#imageWidthimagef1").val(),
					oldHeight1 : $("#imageHeightimagef1").val()
					//company : company
				}, function(data) {
					if (data == "success") {
						 var type = $("#type").val();
						if(type.length<1){
							parent.artPicGrid.loadData();
						}
						
						alert("添加成功！");
					}
					if (data == "error") {
						$.ligerDialog.warn("系统有点抽经，请稍候重试！");
					}
				});
			}
		});
	});

	function uploadImg(self) {
		var filepath = $(self).val();
		var extStart = filepath.lastIndexOf(".");
		var ext = filepath.substring(extStart, filepath.length).toUpperCase();
		if (ext != ".PNG" && ext != ".JPG" && ext != ".JPEG" && ext != ".GIF") {
			alert("图片限于png,jpeg,jpg,gif格式");
			return;
		}
		$("#upload_img_form").ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				var parentId=$(self).attr("id");
				$("#image").val(data.imageServer + data.imageUrl);
				$("#imageWidth"+parentId).val(data.width);
				$("#imageHeight"+parentId).val(data.height);
			
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	function uploadImg2(self) {
		//alert(1111)
		var filepath = $(self).val();
		var extStart = filepath.lastIndexOf(".");
		var ext = filepath.substring(extStart, filepath.length).toUpperCase();
		if (ext != ".PNG" && ext != ".JPG" && ext != ".JPEG" && ext != ".GIF") {
			alert("图片限于png,jpeg,jpg,gif格式");
			return;
		}
		$("#upload_img_form2").ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				$("#image2").val(data.imageServer + data.imageUrl);
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	function uploadImg3(self) {
		//alert(1111)
		var filepath = $(self).val();
		var extStart = filepath.lastIndexOf(".");
		var ext = filepath.substring(extStart, filepath.length).toUpperCase();
		if (ext != ".PNG" && ext != ".JPG" && ext != ".JPEG" && ext != ".GIF") {
			alert("图片限于png,jpeg,jpg,gif格式");
			return;
		}
		$("#upload_img_form3").ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				$("#image3").val(data.imageServer + data.imageUrl);
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	function uploadImg4(self) {
		//alert(1111)
		var filepath = $(self).val();
		var extStart = filepath.lastIndexOf(".");
		var ext = filepath.substring(extStart, filepath.length).toUpperCase();
		if (ext != ".PNG" && ext != ".JPG" && ext != ".JPEG" && ext != ".GIF") {
			alert("图片限于png,jpeg,jpg,gif格式");
			return;
		}
		$("#upload_img_form4").ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				$("#image4").val(data.imageServer + data.imageUrl);
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	function uploadImg5(self) {
		//alert(1111)
		var filepath = $(self).val();
		var extStart = filepath.lastIndexOf(".");
		var ext = filepath.substring(extStart, filepath.length).toUpperCase();
		if (ext != ".PNG" && ext != ".JPG" && ext != ".JPEG" && ext != ".GIF") {
			alert("图片限于png,jpeg,jpg,gif格式");
			return;
		}
		$("#upload_img_form5").ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				$("#image5").val(data.imageServer + data.imageUrl);
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	function previewImg(imageId) {
		var img_url = $("#" + imageId).val();
		if (!IsNull(img_url)) {
			window.open(img_url);
		} else {
			alert("没有图片，请上传！");
		}
	}
	
	$(function() {
		
		$("#parent").ligerComboBox({
			width : 215,
			selectBoxWidth : 215,
			selectBoxHeight : 180,
			valueField : 'id',
			textField : 'text',
			treeLeafOnly : false,
			tree : {
				checkbox : false,
				btnClickToToggleOnly : false,
				url : '/misc/artPic/classTree.htm?type=${classType}'
			}
		});
		if("${parentId}" != "undefined"){
			$("#parent_val").val("${parentId}");
		}
		
	});
</script>
<form id="upload_img_form" enctype="multipart/form-data" method="post"
	action="/misc/artPic/uploadImg.htm">
	<table width="80%" class="def_t" border="1" cellpadding="0"
		cellspacing="0">
		<tr>
			<td style="width: 100px;">作品图1：</td>
			<td colspan="2"><input type="file"
				onchange="uploadImg(this);return false;" style="width: 200px;"
				title="支持jpg、jpeg、gif、png格式，文件小于2M" name="imagef1" id="imagef1" />
				<a href="javascript:;" target="_blank"
				onclick="previewImg('image');">预览</a> <input name="image"
				type="hidden" id="image" value="" />
			</td>
		</tr>
	</table>
	<input type="hidden" id="imageWidthimagef1" />
	<input type="hidden" id="imageHeightimagef1"/>
</form>
<form id="upload_img_form2" enctype="multipart/form-data" method="post"
	action="/misc/artPic/uploadImg.htm">
	<table width="80%" class="def_t" border="1" cellpadding="0"
		cellspacing="0">
		<tr>
			<td style="width: 100px;">作品图2：</td>
			<td colspan="2"><input type="file"
				onchange="uploadImg2(this);return false;" style="width: 200px;"
				title="支持jpg、jpeg、gif、png格式，文件小于2M" name="imagef2" id="imagef2" />
				<a href="javascript:;" target="_blank"
				onclick="previewImg('image2');">预览</a> <input name="image2"
				type="hidden" id="image2" value="" />
			</td>
		</tr>
	</table>
</form>
<form id="upload_img_form3" enctype="multipart/form-data" method="post"
	action="/misc/artPic/uploadImg.htm">
	<table width="80%" class="def_t" border="1" cellpadding="0"
		cellspacing="0">
		<tr>
			<td style="width: 100px;">作品图3：</td>
			<td colspan="2"><input type="file"
				onchange="uploadImg3(this);return false;" style="width: 200px;"
				title="支持jpg、jpeg、gif、png格式，文件小于2M" name="imagef3" id="imagef3" />
				<a href="javascript:;" target="_blank"
				onclick="previewImg('image3');">预览</a> <input name="image3"
				type="hidden" id="image3" value="" />
			</td>
		</tr>
	</table>
</form>
<form id="upload_img_form4" enctype="multipart/form-data" method="post"
	action="/misc/artPic/uploadImg.htm">
	<table width="80%" class="def_t" border="1" cellpadding="0"
		cellspacing="0">
		<tr>
			<td style="width: 100px;">作品图4：</td>
			<td colspan="2"><input type="file"
				onchange="uploadImg4(this);return false;" style="width: 200px;"
				title="支持jpg、jpeg、gif、png格式，文件小于2M" name="imagef4" id="imagef4" />
				<a href="javascript:;" target="_blank"
				onclick="previewImg('image4');">预览</a> <input name="image4"
				type="hidden" id="image4" value="" />
			</td>
		</tr>
	</table>
</form>
<form id="upload_img_form5" enctype="multipart/form-data" method="post"
	action="/misc/artPic/uploadImg.htm">
	<table width="80%" class="def_t" border="1" cellpadding="0"
		cellspacing="0">
		<tr>
			<td style="width: 100px;">作品图5：</td>
			<td colspan="2"><input type="file"
				onchange="uploadImg5(this);return false;" style="width: 200px;"
				title="支持jpg、jpeg、gif、png格式，文件小于2M" name="imagef5" id="imagef5" />
				<a href="javascript:;" target="_blank"
				onclick="previewImg('image5');">预览</a> <input name="image5"
				type="hidden" id="image5" value="" />
			</td>
		</tr>
	</table>
</form>
<form method="post" id="add_artPic_form" action="">
	<table width="80%" class="def_t">
		<tr>
			<td>作者：</td>
			<td>
				<input type="text" id="painter" name="painter" />
				<input type="hidden" id="classId" name="classId" value="${classId }"/>
				<input type="hidden" id="type" name="type" value="${type }"/>
			</td>
		</tr>
		<tr>
			<td>分类：</td>
			<td><input type="text" id="parent"/>
			</td>
		</tr>
		<tr>
			<td>尺寸：</td>
			<td><input type="text" id="artSize" name="artSize" /></td>
		</tr>
		<tr>
			<td>材料：</td>
			<td><input type="text" id="material" name="material" /></td>
		</tr>
		<tr>
			<td>标题：</td>
			<td><input type="text" id="title" name="title" /></td>
		</tr>
		<tr>
			<td>描述：</td>
			<td><textarea id="content" name="content" cols="200"
					style="width: 450px"></textarea></td>
		</tr>
		<tr>
			<td>数量：</td>
			<td><input type="text" id="count" name="count" /></td>
		</tr>
		<tr>
			<td>一口价：</td>
			<td><input type="text" id="priceMax" name="priceMax" />
			</td>
		</tr>
		<tr>
			<td>起拍格：</td>
			<td><input type="text" id="price" name="price" /></td>
		</tr>
		<tr>
			<td>年代：</td>
			<td><input type="text" id="years" name="years" /></td>
		</tr>

		<tr>
			<td colspan="2" style="text-align: center;">
				<button type="submit">确定</button>
			</td>
		</tr>
	</table>
</form>
